var VProxy;
var thisObj;
var LockedVehiclesPageMediator = Objs("view.LockedVehiclesPageMediator",
	Mediator,
{

	initialize: function( name, viewComponent )
	{ 
		
		LockedVehiclesPageMediator.$super.initialize.call( this, name, viewComponent );
    	this.VProxy = this.facade.retrieveProxy( ProxyNames.VEHICLE_PROXY );
		this.registerListeners();
		this.VProxy.getLockedVehicles();
		thisObj = this;
		
	},
	registerListeners: function()
	{   
		//var lockedVehiclesPageView = this.get();
		//lockedVehiclesPageView.addEventListener( LockedVehiclesPage.GET_LOCKED_VEHICLES, this.getLockedVehicles, this );
		
	},
	get: function()
	{
		return this.viewComponent;
	},
	unregisterListeners: function()
	{
	},
	listNotificationInterests: function()
	{
		return [
				NotificationNames.GET_LOCKED
		];
	},
    handleNotification: function( note )
	{ 
		switch ( note.getName() )
		{ 
			case NotificationNames.GET_LOCKED:
		        this.setLockedVehicleList(note.getBody());
				break;
		}
		

	},
	getLockedVehicles: function()
	{ 
		VProxy.getLockedVehicles();
	},
	setLockedVehicleList:function(result)
	{
		var tbodyInnerHtml = "<tbody>";
		var lockedVehicles = result.lockedVehicles;

		$('#locked_vehicles_table tbody').html(" ");
		
		if(lockedVehicles.length>0)
		{
			for(var i=0; i<lockedVehicles.length; i++)
			{
				var row = lockedVehicles[i];
				tbodyInnerHtml += "<tr><td>"+row.vehicle_id+"</td><td>"+row.make+"</td><td>"+row.model+"</td><td>"+row.locked_by+"</td><td>"+row.locked_date+"<td><button id="+row.vehicle_id+" onClick='thisObj.unlockVehicle(this)' class='btn btn-primary'>Unlock</button></td></tr>";
				
			}
			tbodyInnerHtml += "</tbody>";
			var table = $('#locked_vehicles_table');
			table.append(tbodyInnerHtml);
		}

	},
	unlockVehicle:function(button)
	{
		this.VProxy.unlockVehicle(button.id);
	}
	
	
});

